<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>插值表达式</title>
    </head>
    <body>
        <div id="app">
            {{ date }}
        </div>
        <script src="https://unpkg.com/vue/dist/vue.min.js"></script>
        <script>
            var app = new Vue({
                el: '#app',
                data: {
                    date: new Date()
                },
                mounted: function (){
                    var _this = this; //声明一个变量指向Vue实例this，保证作用域一致
                    this.timer = setInterval (function(){
                        _this.date = new Date();//修改数据date
                    },1000);
                },
                beforeDestroy: function(){
                    if (this.timer){
                        clearInterval(this.timer);//在Vue实例销毁前，清除我们的定时器
                    }
                }
            })



        </script>
    </body>
</html>